package com.woniuxy.sale.controller;

import com.woniuxy.commons.annotations.RequirePermission;
import com.woniuxy.commons.entity.sale.SoAccount;
import com.woniuxy.commons.entity.sale.vo.sale.SoAccountUpdateVo;
import com.woniuxy.commons.result.Result;
import com.woniuxy.commons.entity.sale.vo.sale.SoAccountVo;
import com.woniuxy.sale.service.DictService;
import com.woniuxy.sale.service.SoAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO: 对选货单表的控制器
 * <P> Date: 2022/4/19:14:22
 * <P> Description:
 */
@RestController
@RequestMapping("/sale/soAccount")
@Api(tags = "选货单表的控制器")
public class SoAccountController {

    @Resource
    private SoAccountService soAccountService;

    @Resource
    private DictService dictService;

    /**
     * <P>Author ideaAdmin
     * <P>TODO: 查询所有的选货单信息 并分页
     * <P>Date 14:28 2022/4/19
     * <P> *
     * <P>* @return com.woniuxy.commons.result.Result
     **/
    @RequirePermission("system")
    @ApiOperation(value = "查询所有的选货单信息 并分页")
    @PostMapping("/findSoAccountAll/{currentPage}/{limit}")
    public Result findSoAccountAll(@PathVariable("currentPage") Integer currentPage,
                                   @PathVariable("limit") Integer limit,
                                   @RequestBody SoAccountVo soAccountVo) {

        return soAccountService.findSoAccountAll(currentPage, limit, soAccountVo);
    }

    /**
     * <P>Author ideaAdmin
     * <P>TODO: 根据选货单id 获得它所有的选货信息
     * <P>Date 11:42 2022/4/21
     * <P>* @param soId
     * <P>* @return com.woniuxy.commons.result.Result
     **/
    @RequirePermission("addPackingList")
    @ApiOperation(value = "根据选货单id 获得它所有的选货信息 ")
    @PostMapping("/findSoAccountById/{soId}")
    public Result findSoAccountById(@RequestBody SoAccountVo soAccountVo) {
        return soAccountService.findSoAccountById(soAccountVo);
    }


    /**
     * <P>Author ideaAdmin
     * <P>TODO: 添加选货单和对应的选货单产品
     * <P>Date 14:32 2022/4/19
     * <P>* @param soAccount
     * <P>* @return com.woniuxy.commons.result.Result
     **/
    @RequirePermission("addPackingList")
    @ApiOperation(value = "添加选货单和对应的选货单产品")
    @PostMapping("/addAccount")
    public Result addAccount(@RequestBody SoAccount soAccount) {
        return soAccountService.add(soAccount);
    }

    /**
     * <P>Author ideaAdmin
     * <P>TODO: 获得所有的数据字典
     * <P>Date 11:42 2022/4/21
     * <P> *
     * <P>* @return com.woniuxy.commons.result.Result
     **/
    @RequirePermission("addPackingList")
    @ApiOperation(value = "获得所有的数据字典")
    @GetMapping("/dict")
    public Result get() {
        return Result.ok(dictService.findAllDict());
    }


    @RequirePermission("addPackingList")
    @ApiOperation(value = "设置选货单的状态")
    @PostMapping("/updateSoAccountStatus")
    public Result updateSoAccountStatusById(@RequestBody SoAccountUpdateVo soAccountUpdateVo) {
        return soAccountService.updateSoAccountStatusById(soAccountUpdateVo);
    }


}
